<template>
  <user-center-component v-if="isLogin" :user="user" />
  <not-login-component v-else />
</template>

<script>
import { getUserInfo } from "@/api/userCenter";
import NotLoginComponent from "@/components/NotLoginComponent.vue";
import UserCenterComponent from "@/components/UserCenterComponent.vue";

export default {
  components: { UserCenterComponent, NotLoginComponent },
  data() {
    return {
      user: {},
      isLogin: false,
    };
  },
  methods: {
    async getUserInfo(id) {
      const res = await getUserInfo(id);
      if (res.data.success) {
        this.user = res.data.result;
        console.log(this.user);
      } else {
        alert(res.data.msg);
      }
    },
  },
  computed: {
    getLoginInfo() {
      return this.$store.state.user.userInfo.userId;
    },
  },
  created() {
    if (this.$route.params.id) {
      this.isLogin = true;
      let userId = this.$route.params.id;
      console.log("userId:" + userId);
      this.getUserInfo(userId);
    }
  },
};
</script>

<style>
</style>